layui.config({
    base: "js/"
}).use(['table', 'layer', 'form', 'jquery'], function () {
    var table = layui.table,
        form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        $ = layui.jquery;

    var myDate = new Date();
    $(".year").html(myDate.getFullYear());


    /**
     * 查询未签到的同学
     */
    $.ajax({
        url: "../../home/queryNoCheckingIn",
        type: 'get',
        success: function (data) {
            if (data.code == 200) {
                $(".noCheckingInNum").text(data.data.length)
                $(".dn").bind("click", function () {
                    var str = "";
                    $.each(data.data, function (v, o) {
                        str += '<div>';
                        str += '<p>' + o.userName + '</p>';
                        str += '</div>';
                    });
                    $('.noCheckingIn').html(str);
                    $(".noCheckingIn").toggle(1000);

                })

            }

        },
        error: function () {
            $.message({
                message: "boom..",
                type: 'error',
                showClose: true
            });

        }
    });

    /**
     * 查询已签到的同学
     */
    $.ajax({
        url: "../../home/queryCheckingIn",
        type: 'get',
        success: function (data) {
            if (data.code == 200) {
                $(".checkingInNum").text(data.data.length)
                $(".up").bind("click", function () {
                    var str = "";
                    $.each(data.data, function (v, o) {
                        str += '<div>';
                        str += '<p>' + o.userName + '</p>';
                        str += '</div>';
                    });
                    $('.checkingIn').html(str);
                    $(".checkingIn").toggle(1000);

                })

            }

        },
        error: function () {
            $.message({
                message: "boom..",
                type: 'error',
                showClose: true
            });

        }
    });


    /**
     * 监听提交
     */
    form.on('submit(changeUser)', function (data) {

        if ($("input[name='userName']").val() == '') {
            $.message({
                message: "请输入用户名",
                type: 'warning',
                showClose: true
            });
            return false;
        }



        /**
         * 又换了种风格，并且设定最长等待10秒
         */
        var index = layer.load(2, {time: 10 * 5000});

        $.ajax({
            url: "../../home/checkingIn",
            type: 'post',
            dataType: 'json',
            contentType: 'application/json;charset=utf-8',
            data: JSON.stringify(data.field),
            success: function (data) {
                layer.close(index);
                console.log(data)

                if (data.code == 200) {
                    $.message({
                        message: data.msg,
                        type: 'success',
                        showClose: true
                    });
                } else {
                    $.message({
                        message: data.msg,
                        type: 'warning',
                        showClose: true
                    });
                }
            },
            error: function () {
                layer.close(index);
                $.message({
                    message: "boom..",
                    type: 'error',
                    showClose: true
                });

            }
        });

        return false;
    })


})
;

